package online.sh.cn.fy.users.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;
import online.sh.cn.fy.common.utils.CookieUtil;
import online.sh.cn.fy.common.utils.ResponseUtils;
import online.sh.cn.fy.common.utils.TokenUtils;

/**
 * 根据学校加载对应楼信息
 */
@WebServlet("/signupschool")
public class SignUpSchoolServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		String openid=CookieUtil.getCookieValueByName(request, "openid");
		JSONObject json=new JSONObject();
		if(null==openid || ""!=openid){
			TokenUtils tu=new TokenUtils();
			String shname=request.getParameter("school");
			List school=tu.checkFloorBySchool(shname);
			String result="";
			if(null!=school && school.size()!=0){
				for (int i = 0; i < school.size(); i++) {
					result+="<option value='"+school.get(i)+"'>"+school.get(i)+"</option>";
				}
				result="<option value='' selected='selected'>楼</option>"+result;
			}else{
				result="<option value='' selected='selected'>楼</option><option value=''>无</option>";
			}
            json.put("result", 0);
            json.put("school", result);
            ResponseUtils.renderJson(response, json.toString());
		}else{
			json.put("result", 1);
			ResponseUtils.renderJson(response, json.toString());
		}
	}

}
